﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="ManagerAccount.aspx.cs" Inherits="ManagerAccount" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <script>
        $(document).ready(function () {
            var userid = '<%=Session["Userid"]%>';
            LoadUser(userid);
            changepass(userid);
        });

        function LoadUser(userid) {
            $.ajax({
                type: "POST",
                url: "PIMService.asmx/GetUserById",
                data: "{'_userId':'" + userid + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var user = result.d;
                    var username = user.UserName;
                    var Password = user.Password;
                    $('#manager_username').val(username);
                    $('#manager_old_password').val(Password);
                },
                error: function (result) {
                    alert('Error');
                }
            });
        }

        function changepass(userid) {
            $('#changepassword').click(function () {
                if ($("#manager_username").val() == '') {
                    alert('Please input username or email!');
                    $("#manager_username").focus();
                }
                else if ($("#manager_new_password").val() == '') {
                    alert('Please input password');
                    $("#manager_new_password").focus();
                }
                else if ($("#manager_confirm_new_password").val() == '') {
                    alert('Please input password to confirm');
                    $("#manager_confirm_new_password").focus();
                }
                else if ($("#manager_new_password").val() != $("#manager_confirm_new_password").val()) {
                    alert('Password is not mark!');
                    $("#manager_confirm_new_password").val("");
                    $("#manager_confirm_new_password").focus();
                }
                else {
                    $.ajax({
                        type: "POST",
                        url: "PIMService.asmx/ChangePassword",
                        data: "{'_userId':'" + userid + "','_password':'" + $("#manager_new_password").val() + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (result) {
                            if (result.d == 'NotOK' || result.d == '') {
                                alert('Change password is fail!');
                            }
                            else {
                                self.location = "Default.aspx"
                            }
                        },
                        error: function (result) {
                            alert('Can not change password!');
                        }
                    });
                }
            });
        }

    </script>
    <div id="content" class="clearfix">
        <div class="createuser clearfix">
            <div class="bg01">
                <div class="bg02">
                    <%--<div class="bg03 clearfix">--%>
                    <div class="bg03 clearfix" style="height:410px; padding:20px;">
                        <form method="post" action="#">
                        <div style="width:50%;margin:0 auto">
                        <div class="accountdiv">
                            <p style="text-align:center;font-size:16px;font-weight:bold">Change Password</p>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            Email Address:
                            </div>
                            <div class="form-filed-account">
                            <input class="field-textbox1" name="email" id="manager_username" readonly="readonly" type="text" autocomplete="on"
                                >
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            Old Password:
                            </div>
                            <div class="form-filed-account">
                            <input  class="field-textbox1" name="oldpassword" id="manager_old_password" readonly="readonly" type="password"
                               >
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            New Password:
                            </div>
                            <div class="form-filed-account">
                                <input  class="field-textbox1" name="newpassword" id="manager_new_password" type="password" >
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            Confirm New Password:
                            </div>
                            <div class="form-filed-account">
                            <input  class="field-textbox1" name="confirmnewpassword" id="manager_confirm_new_password" type="password"
                                placeholder="Password">
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv" style="text-align:center;">
                            <input  id="changepassword" class="button-form" value="Change password" type="button">
                        </div>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
